// downloadImage.js

const http = require('http');
const fs = require('fs');

// 下载网络图片并保存到本地
function downloadImage(url, filename) {
  const file = fs.createWriteStream(filename);
  http.get(url, (res) => {
    res.pipe(file);
    console.log(`${filename} 下载完成`);
  });
}

downloadImage('http://www.example.com/image.jpg', 'image.jpg');
